﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.LuFang.API.Application.Command.imgCommand;
using RBAC.LuFang.API.Application.Command.slaughterCommand;
using RBAC.LuFang.API.Dtos;
using RBAC.LuFang.Domain.DTO;
using RBAC.LuFang.Domain.Traceability;
using RBAC.LuFang.Repository.lmpl;
using System.Collections.Generic;

namespace RBAC.LuFang.API.Controllers
{
    /// <summary>
    /// 屠宰控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class slaughterController : ControllerBase
    {
        private readonly IMediator _mediator;

        public slaughterController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 更新屠宰信息
        /// </summary>
        /// <param name="slaughter"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> Updslaughter(slaughterUpdCommand slaughter)
        {
            ApiResult<int> result=new ApiResult<int>();
            try
            {
                result.Data = await _mediator.Send(slaughter);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 反填屠宰信息
        /// </summary>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<slaughter>> Fanslaughter(slaughterFanCommand goodsid)
        {
            ApiResult<slaughter> result=new ApiResult<slaughter>();
            try
            {
               result.Data=await _mediator.Send(goodsid);   
            }
            catch (Exception ee) 
            {
                result.Code= -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 显示屠宰信息
        /// </summary>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<List<slaughter>>> Getsla(slaughterSelCommand goodsid)
        {
            ApiResult<List<slaughter>> result=new ApiResult<List<slaughter>>();
            try
            {
                result.Data = await _mediator.Send(goodsid);
            }
            catch (Exception ee)
            {
                result.Code=-1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 显示相关资质
        /// </summary>
        /// <param name="imgtype"></param>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<imges>>> GetRelatedPic([FromQuery]imgRelatedCommand imgRelated)
        {
            ApiResult<List<imges>> result = new ApiResult<List<imges>>();
            try
            {
                result.Data = await _mediator.Send(imgRelated);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 删除相关资质
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelRelatedPid(imgRelatedDelCommand id)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await _mediator.Send(id);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 显示屠宰下的企业信息
        /// </summary>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<List<GetslaEnterpriseDTO>>> GetslaEnterprise(slaEnterpriseSelCommand goodsid)
        {
            ApiResult<List<GetslaEnterpriseDTO>> result=new ApiResult<List<GetslaEnterpriseDTO>>();
            try
            {
                result.Data=await _mediator.Send(goodsid);
            }
            catch (Exception ee)
            {
                result.Code= -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 反填屠宰下的企业信息
        /// </summary>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<Enterprise>> FanslaEnterprise(FanslaEnterpriseCommand goodsid)
        {
            ApiResult<Enterprise> result=new ApiResult<Enterprise>();
            try
            {
               result.Data=await _mediator.Send(goodsid);
            }
            catch (Exception ee)
            {
                result.Code=-1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 更新屠宰下的企业信息
        /// </summary>
        /// <param name="enterprise"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> updslaEnterprise(updslaEnterpriseCommand enterprise)
        {
            ApiResult<int> result=new ApiResult<int>();
            try
            {
                result.Data=await _mediator.Send(enterprise);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 显示屠宰下的企业照片
        /// </summary>
        /// <param name="imgtype"></param>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<imges>>> GetslaEnterPic([FromQuery]GetslaEnterPicCommand getsla)
        {
            ApiResult<List<imges>> result = new ApiResult<List<imges>>();
            try
            {
                result.Data = await _mediator.Send(getsla);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 删除屠宰下的企业照片
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelslaEnterPic(DelslaEnterPicCommand id)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data=await _mediator.Send(id);
            }
            catch (Exception ee)
            {
                result.Code= -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }

























    }
}
